import 'package:flutter/material.dart';

class NavDrawerExample extends StatelessWidget {
  const NavDrawerExample({super.key});

  @override
  Widget build(BuildContext context) {
    const drawerHeader = UserAccountsDrawerHeader(
      accountName: Text('User Name'),
      accountEmail: Text('user.name@email.com'),
      currentAccountPicture: CircleAvatar(
        backgroundColor: Colors.white,
        child: FlutterLogo(size: 42.0),
      ),
      otherAccountsPictures: <Widget>[
        CircleAvatar(backgroundColor: Colors.yellow, child: Text('A')),
        CircleAvatar(backgroundColor: Colors.red, child: Text('B')),
      ],
    );
    final drawerItems = ListView(
      children: <Widget>[
        drawerHeader,
        ListTile(
          title: const Text('To page 1'),
          onTap: () => Navigator.of(context).push(_NewPage(1)),
        ),
        ListTile(
          title: const Text('To page 2'),
          onTap: () => Navigator.of(context).push(_NewPage(2)),
        ),
        ListTile(title: const Text('other drawer item'), onTap: () {}),
      ],
    );
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.amber,
        title: const Text('Drawer example'),
      ),
      body: const Center(
        child: Text('Swip or click upper-left icon to see drawer.'),
      ),
      drawer: Drawer(child: drawerItems),
    );
  }
}

// <void> means this route returns nothing.
class _NewPage extends MaterialPageRoute<void> {
  _NewPage(int id)
    : super(
        builder: (BuildContext context) {
          return Scaffold(
            appBar: AppBar(title: Text('Page $id'), elevation: 1.0),
            body: Center(child: Text('Page $id')),
          );
        },
      );
}
